<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>localStorage</h1>
    <hr>
    <button id="btn01">存</button>
    <button id="btn02">取</button>
    <hr>
    <script>
        const btn01 = document.getElementById("btn01")
        const btn02 = document.getElementById("btn02")

        btn01.onclick = () => {
            // console.log(sessionStorage);
            // setItem() 用来存储数据
            // getItem() 用来获取数据
            // removeItem() 用来删除数据
            // clear() 用来清空数据
            
            localStorage.setItem("name","孙悟空")
            localStorage.setItem("age","年龄")
            localStorage.setItem("gender","性别")
            localStorage.setItem("address","花果山")
        }
        btn02.onclick = () => {
            const name = localStorage.getItem("name")
            const age = localStorage.getItem("age")
            const gender = localStorage.getItem("gender")
            const address = localStorage.getItem("address")
            console.log(name);
            // sessionStorage.clear() 清空
        }
    </script>

</body>
</html>